﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_Controls_page_center_doublepanel : System.Web.UI.UserControl
{
    Common _common = null;
    DataTable dttLeft,dttRight;
    public string type = "";
    public string[] doituong;
    Control ct;
    protected void Page_Load(object sender, EventArgs e)
    {
        _common = new Common();
        if (!string.IsNullOrEmpty(this.SkinID.ToString())) doituong = this.SkinID.ToString().Split('-');//1-9
        if (doituong.Length > 1)
        {
            string[] sTintuc;
                //Lấy ra các thông tin của trang và danh sách các control tương ứng
            string sql_select = "SELECT * FROM CreatePages_block where id_block="+doituong[0].ToString();
            dttLeft = _common.getDataTable(sql_select);
            sql_select = "SELECT * FROM CreatePages_block where id_block=" + doituong[1].ToString();
            dttRight = _common.getDataTable(sql_select);

            if (dttLeft.Rows.Count>0)
            {
                if (!(String.IsNullOrEmpty(dttLeft.Rows[0]["path"].ToString())))
                {
                    sTintuc = dttLeft.Rows[0]["path"].ToString().Split('?');
                    if (sTintuc.Length > 1)
                    {
                        ct = Page.LoadControl(sTintuc[0].ToString());
                        ct.SkinID = sTintuc[1].ToString();
                    }
                    else
                    {
                        ct = Page.LoadControl(dttLeft.Rows[0]["path"].ToString());
                    }
                    panel_sub_left.Controls.Add(ct);
                }
            }

            if (dttRight.Rows.Count > 0)
            {
                if (!(String.IsNullOrEmpty(dttRight.Rows[0]["path"].ToString())))
                {
                    sTintuc = dttRight.Rows[0]["path"].ToString().Split('?');
                    if (sTintuc.Length > 1)
                    {
                        ct = Page.LoadControl(sTintuc[0].ToString());
                        ct.SkinID = sTintuc[1].ToString();
                    }
                    else
                    {
                        ct = Page.LoadControl(dttRight.Rows[0]["path"].ToString());
                    }
                    panel_sub_right.Controls.Add(ct);
                }
            }
        }
        
    }
}
